//
//  YHContributionHeaderView.m
//  Catches
//
//  Created by jiangqiong on 2018/5/17.
//  Copyright © 2018年 solot. All rights reserved.
//

#import "YHContributionHeaderView.h"


@interface YHContributionHeaderView()
@property (nonatomic , strong)UILabel * labAddress;
@property (nonatomic , strong)UIImageView * imgFlag;
@property (nonatomic , strong)UILabel * labName;

@property (nonatomic , strong)YHContributionerModel * model;

@property (nonatomic , strong)UIImageView * avaterImg;
@property (nonatomic , strong)UILabel * labLevel;
@property (nonatomic , strong)UILabel * labContribute;

@end

@implementation YHContributionHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = COLOR_WITH_HEX(0xf6f6f6);
        
        [self setupUI];
    }
    return self;
}

-(void)setupUI{
    UIView * centerView = [UIView new];
    [self addSubview:centerView];
    [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.width.mas_equalTo(150);
        make.top.offset(0);
        make.bottom.offset(0);
    }];
    
    UIImageView * topImg = [UIImageView new];
    [centerView addSubview:topImg];
    topImg.image = [UIImage imageNamed:@"fish_disdinguish_head"];
    [topImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(10);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo((266.0/225.0)*80);
        make.centerX.offset(0);
    }];
    
    UIImageView * avaterImg = [UIImageView new];
    [centerView addSubview:avaterImg];
    avaterImg.image = [UIImage imageNamed:@"mine_bag_boat_v2"];
    [avaterImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(topImg.mas_centerY).offset(7.5);
        make.centerX.offset(0);
        make.width.height.mas_equalTo(75);
    }];
    avaterImg.layer.cornerRadius = 37.5;
    avaterImg.layer.masksToBounds = YES;
    self.avaterImg = avaterImg;
    
    UIImageView * bottomImg = [UIImageView new];
    [centerView addSubview:bottomImg];
    bottomImg.image = [UIImage imageNamed:@"fish_disdinguish_itemBg"];
    [bottomImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.offset(0);
        make.top.mas_equalTo(topImg.mas_bottom).offset(-10);
    }];
    
    UILabel * levelLab = [UILabel new];
    [bottomImg addSubview:levelLab];
    levelLab.text = @"院士";
    levelLab.font = [UIFont systemFontOfSize:12];
    levelLab.textColor = [UIColor whiteColor];
    levelLab.textAlignment = NSTextAlignmentCenter;
    [levelLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.offset(0);
        make.centerY.offset(-5);
        
    }];
    self.labLevel = levelLab;
    
    UILabel * nameLab = [UILabel new];
    self.labName = nameLab;
    [centerView addSubview:nameLab];
    nameLab.textAlignment = NSTextAlignmentCenter;
    nameLab.textColor = COLOR_WITH_HEX(0x000000);
    nameLab.text = @"小李飞龙飞";
    [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.offset(0);
        make.bottom.offset(-40);
        
    }];
    self.labName = nameLab;
    
    UIImageView * flagImg = [UIImageView new];
    self.imgFlag = flagImg;
    [centerView addSubview:flagImg];
    flagImg.image = [UIImage imageNamed:@"mine_bags_tools"];
    [flagImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(10);
        make.leading.offset(45);
        make.bottom.offset(-20);
    }];
    
    UILabel * addressLab = [UILabel new];
    self.labAddress = addressLab;
    [centerView addSubview:addressLab];
    addressLab.textColor = [UIColor grayColor];
    addressLab.font = [UIFont systemFontOfSize:10];
    addressLab.text = @"成都";
    [addressLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(flagImg.mas_centerY).offset(0);
        make.leading.mas_equalTo(flagImg.mas_trailing).offset(10);
    }];
    
    UILabel * numberLab = [UILabel new];
    [self addSubview:numberLab];
    numberLab.textAlignment = NSTextAlignmentCenter;
    numberLab.font = [UIFont systemFontOfSize:18];
    numberLab.textColor = COLOR_WITH_HEX(0x000000);
    numberLab.text = @"No.1";
    [numberLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.offset(70);
        make.leading.offset(0);
        make.trailing.mas_equalTo(centerView.mas_leading).offset(0);
    }];
    
    UILabel * rankLab = [UILabel new];
    [self addSubview:rankLab];
    rankLab.textAlignment = NSTextAlignmentCenter;
    rankLab.font = [UIFont systemFontOfSize:10];
    rankLab.textColor = COLOR_WITH_HEX(0x666666);
    rankLab.text = @"贡献值";
    [rankLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top. mas_equalTo(numberLab.mas_bottom).offset(10);
        make.leading.offset(0);
        make.trailing.mas_equalTo(centerView.mas_leading).offset(0);
    }];
    
    UILabel * valueLab = [UILabel new];
    [self addSubview:valueLab];
    valueLab.textAlignment = NSTextAlignmentCenter;
    valueLab.font = [UIFont systemFontOfSize:18];
    valueLab.textColor = COLOR_WITH_HEX(0x000000);
    valueLab.text = @"3876";
    [valueLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.offset(70);
        make.trailing.offset(0);
        make.leading.mas_equalTo(centerView.mas_trailing).offset(0);
    }];
    self.labContribute = valueLab;
    
    UILabel * contributLab = [UILabel new];
    [self addSubview:contributLab];
    contributLab.textAlignment = NSTextAlignmentCenter;
    contributLab.font = [UIFont systemFontOfSize:10];
    contributLab.textColor = COLOR_WITH_HEX(0x666666);
    contributLab.text = @"贡献值";
    [contributLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(numberLab.mas_bottom).offset(10);
        make.trailing.offset(0);
        make.leading.mas_equalTo(centerView.mas_trailing).offset(0);
    }];
}

-(void)areaFaramChange{
    self.labAddress.hidden = YES;
    self.imgFlag.hidden = YES;
    [self.labName mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.offset(0);
        make.bottom.offset(-30);
    }];
}


-(void)installData:(YHContributionerModel *)model{
    self.model = model;
    if(model.areaType == YHContributionAreaType_area){
        [self areaFaramChange];
    }
    
    [self.avaterImg setImageWithImageId:model.avatar];
    self.labName.text = model.nickname;
    self.labLevel.text =@"sddjk";
    self.labContribute.text = [NSString stringWithFormat:@"%ld",model.contributiveScore];
    
   
    
    
   
}

@end
